package com.example.viewtestapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private ImageView splashImage;//渐隐动画的view
    private ImageView animatorIv;//缩小动画的view
    private ImageView btnIv;//最后的的按钮图标
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        splashImage=findViewById(R.id.splash_image_view);
        animatorIv=findViewById(R.id.animator_iv);
        btnIv=findViewById(R.id.btn_iv);
        btnIv.setVisibility(View.GONE);
        AlphaAnimation outAnimation=new AlphaAnimation(1,0);
        outAnimation.setDuration(2000);
        splashImage.startAnimation(outAnimation);
        outAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                splashImage.setVisibility(View.GONE);
                setAnimatorIv();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    private void setAnimatorIv(){
        Animation smallAnimation= AnimationUtils.loadAnimation(this,R.anim.iv_scale_anima);
        Animation moveAnimation= AnimationUtils.loadAnimation(this,R.anim.anima_down);
        AnimationSet smallMoveSet=new AnimationSet(true);
        smallMoveSet.addAnimation(smallAnimation);
        smallMoveSet.addAnimation(moveAnimation);
        //smallMoveSet.setFillAfter(true);
        animatorIv.startAnimation(smallMoveSet);
        smallMoveSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                animatorIv.setVisibility(View.GONE);
                btnIv.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}
